package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.label.LabelDto;
import com.java110.intf.goods.ILabelInnerServiceSMO;
import com.java110.mall.goods.dao.ILabelServiceDao;
import com.java110.po.label.LabelPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 标签信息内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class LabelInnerServiceSMOImpl extends BaseServiceSMO implements ILabelInnerServiceSMO {

    @Autowired
    private ILabelServiceDao labelServiceDaoImpl;


    @Override
    public int saveLabel(@RequestBody LabelPo labelPo) {
        int saveFlag = 1;
        labelServiceDaoImpl.saveLabelInfo(BeanConvertUtil.beanCovertMap(labelPo));
        return saveFlag;
    }

    @Override
    public int updateLabel(@RequestBody LabelPo labelPo) {
        int saveFlag = 1;
        labelServiceDaoImpl.updateLabelInfo(BeanConvertUtil.beanCovertMap(labelPo));
        return saveFlag;
    }

    @Override
    public int deleteLabel(@RequestBody LabelPo labelPo) {
        int saveFlag = 1;
        labelPo.setStatusCd("1");
        labelServiceDaoImpl.updateLabelInfo(BeanConvertUtil.beanCovertMap(labelPo));
        return saveFlag;
    }

    @Override
    public List<LabelDto> queryLabels(@RequestBody LabelDto labelDto) {

        //校验是否传了 分页信息

        int page = labelDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            labelDto.setPage((page - 1) * labelDto.getRow());
        }

        List<LabelDto> labels = BeanConvertUtil.covertBeanList(labelServiceDaoImpl.getLabelInfo(BeanConvertUtil.beanCovertMap(labelDto)), LabelDto.class);

        return labels;
    }


    @Override
    public int queryLabelsCount(@RequestBody LabelDto labelDto) {
        return labelServiceDaoImpl.queryLabelsCount(BeanConvertUtil.beanCovertMap(labelDto));
    }

    public ILabelServiceDao getLabelServiceDaoImpl() {
        return labelServiceDaoImpl;
    }

    public void setLabelServiceDaoImpl(ILabelServiceDao labelServiceDaoImpl) {
        this.labelServiceDaoImpl = labelServiceDaoImpl;
    }
}
